<template>
    <div class="meituanLogin">
        <div class="back"><span class="iconfont" @click="back">&#xe613;</span></div>
        <div class="user">
            <div class="userInfo">
                <input type="text" v-model="username" placeholder="账户名/手机号/Email">
            </div>
            <div class="userInfo">
                <input type="password" v-model="password" placeholder="请输入密码">
            </div>
        </div>
        <button class="mint-button mint-button--danger mint-button--large login" @click="login"> <label class="mint-button-text">登录</label></button>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                username: '',
                password: ''
            }
        },
        methods: {
            login() {
                sessionStorage.setItem('token', '')

                if (localStorage.getItem(this.username)) {
                    // 手动制作令牌
                    let token = this.username
                    sessionStorage.setItem("token", token)

                    console.log(sessionStorage.getItem('token'))

                    let path = this.$route.query.redirect
                    if (path) {
                        this.$router.push(path)
                    } else {
                        this.$router.push('/')
                    }
                }
                else {
                    alert("该账户没有注册，请注册！")
                    this.$router.push('/register')
                }
            },
            back() {
                this.$router.push("/")
            }
        }
    }
</script>

<style scoped lang="scss">
    .meituanLogin {
        padding: 0 0.24rem;
        .back {
            position: absolute;
            top: 0.27rem;
            left: 0.16rem;
            z-index: 33000;

        }
        .user {
            width: 100%;
            .userInfo {
                height: .9rem;
                border-bottom: 0.02rem solid #d6d6d6;
                input {
                    width: 100%;
                    border: 0;
                    outline: none;
                    height: .5rem;
                    text-indent: .1rem;
                    line-height: 1;
                    font-size: 0.28rem;
                    border-radius: .06rem;
                    margin: .2rem 0;
                }
                input:focus {
                    background-color: #f8f8f8;
                    border: 0;
                }
            }
        }
        .login {
            height: .6rem;
            margin-top: 10px;
            font-size: .28rem;
        }
    }
</style>